import java.util.Arrays;
import java.util.Scanner;

public class Test2 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        long[] a = new long[n];
        for (int i = 0; i < n; i++) {
            a[i] = in.nextLong();
        }

        long[] dp = new long[k];
        Arrays.fill(dp, Long.MIN_VALUE / 2); // 避免溢出
        dp[0] = 0; // 空集

        for (long num : a) {
            long[] next = dp.clone();
            for (int r = 0; r < k; r++) {
                if (dp[r] > Long.MIN_VALUE / 2) {
                    int newR = (int)((r + num) % k);
                    next[newR] = Math.max(next[newR], dp[r] + num);
                }
            }
            dp = next;
        }

        // 输出结果
        if (dp[0] > 0) {
            System.out.println(dp[0]);
        } else {
            System.out.println(-1);
        }
    }
}
